<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\DB;

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('users', function (Blueprint $table) {
            $table->decimal('money', 12, 2)->default(0)->comment("账户金额")->after('kyc');
        });

        Schema::create('users_money_log', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger("user_id")->comment("用户id");
            $table->decimal('money', 12)->default(0)->comment("金额数");
            $table->text("comment")->comment("备注");
            $table->unsignedTinyInteger('category')->default(0)->comment("操作类型: 1充值 2提现 3转入 4转出  5冲正 6消费");
            $table->timestamps();
            $table->index("user_id");
        });
        DB::statement("ALTER TABLE `users_money_log` COMMENT='用户资金流水表'");
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('users', function (Blueprint $table) {
            $table->dropColumn(['money']);
        });

        Schema::dropIfExists('users_money_log');
    }
};
